{% extends 'base.html' %}
{% load widget_tweaks %}

{% block content %}
<h4>{% if object %}编辑违纪记录{% else %}新增违纪记录{% endif %}</h4>
<form method="post">
    {% csrf_token %}
    <div class="mb-3">
        {{ form.student.label_tag }}
        {{ form.student|add_class:'form-control' }}
        {% if form.student.errors %}
            <div class="invalid-feedback d-block">{{ form.student.errors|join:', ' }}</div>
        {% endif %}
    </div>
    <div class="mb-3">
        {{ form.discipline_type.label_tag }}
        {{ form.discipline_type|add_class:'form-control' }}
        {% if form.discipline_type.errors %}
            <div class="invalid-feedback d-block">{{ form.discipline_type.errors|join:', ' }}</div>
        {% endif %}
    </div>
    <div class="mb-3">
        {{ form.happened_at.label_tag }}
        {{ form.happened_at|add_class:'form-control'|attr:'type:date' }}
        {% if form.happened_at.errors %}
            <div class="invalid-feedback d-block">{{ form.happened_at.errors|join:', ' }}</div>
        {% endif %}
    </div>
    <div class="mb-3">
        <div class="mb-3">
        {{ form.place.label_tag }}
        {{ form.place|add_class:'form-control' }}
        {% if form.place.errors %}
            <div class="invalid-feedback d-block">{{ form.place.errors|join:', ' }}</div>
        {% endif %}
    </div>
    <div class="mb-3">
        {{ form.punishment.label_tag }}
        {{ form.punishment|add_class:'form-control'|attr:'rows:3' }}
        {% if form.punishment.errors %}
            <div class="invalid-feedback d-block">{{ form.punishment.errors|join:', ' }}</div>
        {% endif %}
    </div>
    <div class="mb-3">
        {{ form.points_deducted.label_tag }}
        {{ form.points_deducted|add_class:'form-control'|attr:'type:number'|attr:'min:0'|attr:'max:100' }}
        {% if form.points_deducted.errors %}
            <div class="invalid-feedback d-block">{{ form.points_deducted.errors|join:', ' }}</div>
        {% endif %}
    </div>
    {{ form.description.label_tag }}
        {{ form.description|add_class:'form-control'|attr:'rows:3' }}
        {% if form.description.errors %}
            <div class="invalid-feedback d-block">{{ form.description.errors|join:', ' }}</div>
        {% endif %}
    </div>
    <button type="submit" class="btn btn-primary">提交</button>
    <a href="{% url 'core:discipline_record_list' %}" class="btn btn-secondary">返回列表</a>
</form>
{% endblock %}